package zsw.io;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TestSerronized {
	public static void main(String[] args) throws Exception, IOException {
		Dog dog=new Dog();
		dog.setAge("12");
		dog.setDogName("Tom");
		
		ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream(new File("E:/d.txt")));
		objectOutputStream.writeObject(dog);
		objectOutputStream.close();
		
		
		ObjectInputStream inputStream=new ObjectInputStream(new FileInputStream(new File("E:/d.txt")));
		Dog readObject = (Dog) inputStream.readObject();
		System.out.println(readObject.getAge());
		System.out.println(readObject==dog);
		inputStream.close();
		
		
		ByteArrayOutputStream out=new ByteArrayOutputStream();
		ObjectOutputStream objectOutputStream2=new ObjectOutputStream(out);
		objectOutputStream2.writeObject(dog);
		
		ByteArrayInputStream arrayInputStream=new ByteArrayInputStream(out.toByteArray());
		ObjectInputStream inputStream2=new ObjectInputStream(arrayInputStream);
		Dog readObject2 = (Dog) inputStream2.readObject();
		System.out.println(readObject2.getDogName());
		System.out.println(readObject2==dog);
		objectOutputStream2.close();
		inputStream2.close();
	}
	
	

}
